package com.ruoyi.web.controller.Tour;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TourComment;
import com.ruoyi.system.service.ITourCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论管理Controller
 *
 * @author once
 * @date 2020-10-02
 */
@RestController
@RequestMapping("/Tour/comment")
public class TourCommentController extends BaseController
{
    @Autowired
    private ITourCommentService tourCommentService;

    /**
     * 查询评论管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(TourComment tourComment)
    {
        startPage();
        List<TourComment> list = tourCommentService.selectTourCommentList(tourComment);
        return getDataTable(list);
    }

    /**
     * 导出评论管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:comment:export')")
    @Log(title = "评论管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TourComment tourComment)
    {
        List<TourComment> list = tourCommentService.selectTourCommentList(tourComment);
        ExcelUtil<TourComment> util = new ExcelUtil<TourComment>(TourComment.class);
        return util.exportExcel(list, "comment");
    }

    /**
     * 获取评论管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('Tour:comment:query')")
    @GetMapping(value = "/{commentid}")
    public AjaxResult getInfo(@PathVariable("commentid") Long commentid)
    {
        return AjaxResult.success(tourCommentService.selectTourCommentById(commentid));
    }

    /**
     * 新增评论管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:comment:add')")
    @Log(title = "评论管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourComment tourComment)
    {
        return toAjax(tourCommentService.insertTourComment(tourComment));
    }

    /**
     * 修改评论管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:comment:edit')")
    @Log(title = "评论管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourComment tourComment)
    {
        return toAjax(tourCommentService.updateTourComment(tourComment));
    }

    /**
     * 删除评论管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:comment:remove')")
    @Log(title = "评论管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentids}")
    public AjaxResult remove(@PathVariable Long[] commentids)
    {
        return toAjax(tourCommentService.deleteTourCommentByIds(commentids));
    }
}
